﻿using DatabaseAccess;
using Liguo.AppCode;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Liguo.Store
{
    public partial class Registed : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Session["User"] != null)
            {
                User user = (User)Session["User"];
                if (user.Status == 1)
                {
                    Response.Write("<script>alert('您的账号已经激活！');</script>");
                    Response.Write("<script>top.location=\"Store.aspx\";</script>");
                }
                else if (user.Status == 0)
                {
                    Response.Write("<script>alert('您的账号已经被封！');</script>");
                    Response.Write("<script>top.location=\"Banned.aspx\";</script>");
                }
            }
            else if (Session["UserName"] == null || Session["MailBox"] == null)
            {
                Response.Write("<script>alert('您还未登录，请登录！');</script>");
                Response.Write("<script>top.location=\"Port.aspx?mod=Login\";</script>");
            }
        }

        protected void BtSendEmail_Click(object sender, EventArgs e)
        {
            SendEmail();
        }

        private void SendEmail()
        {
            if (Session["User"] != null)
            {
                User user = (User)Session["User"];
                if (user.Status == 1)
                {
                    Response.Write("<script>alert('您的账号已经激活！');</script>");
                    Response.Write("<script>top.location=\"Store.aspx\";</script>");
                }
                else if (user.Status == 0)
                {
                    Response.Write("<script>alert('您的账号已经被封！');</script>");
                    Response.Write("<script>top.location=\"Banned.aspx\";</script>");
                }
            }
            else if (Session["UserID"] == null || Session["UserName"] == null || Session["MailBox"] == null)
            {
                Response.Write("<script>alert('您还未登录，请登录！');</script>");
                Response.Write("<script>top.location=\"Port.aspx?mod=Login\";</script>");
            }
            else
            {
                int UserID = Convert.ToInt32(Session["UserID"]);
                String UserName = Session["UserName"].ToString();
                String MailBox = Session["MailBox"].ToString();
                Dictionary<string, string> info = new Dictionary<string, string>();
                String XCode = Utilities.RandomString(64);
                info["XCode"] = XCode;
                info["XTime"] = DateTime.Now.ToString("yyy-MM-dd HH:mm:ss");
                new SqlIt().UpdateMess("UserInfo", info, "ID='" + UserID + "'");
                new EMail().SendActiveMessage(UserName, MailBox, XCode);
                Response.Write("<script>alert('激活邮件发送成功！');</script>");
            }
        }
    }
}
